package cn.wjzhang.middle.modules.global.controller;

import cn.hutool.extra.spring.SpringUtil;
import cn.wjzhang.core.beans.vo.Result;
import cn.wjzhang.middle.modules.global.service.WjBaseService;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 接口调用 全局统一入口
 * @author wjzhang
 * @date 2021/10/27 14:39
 */
@Api(tags = "全局统一入口")
@RestController
public class GlobalController {

    /**
     * 全局统一入口
     * @param reqJsonObject 请求参数
     * @return 结果
     */
    @ApiOperation("全局统一入口")
    @RequestMapping(value = "/global", consumes = "application/json;charset=utf-8", produces = "application/json;charset=utf-8",
            method = RequestMethod.POST)
    public Result<?> console(@RequestBody JSONObject reqJsonObject) {
        String funcName = reqJsonObject.getString("funcName");
        WjBaseService service = SpringUtil.getBean(funcName,WjBaseService.class);
        return service.execute(reqJsonObject);
    }

    /**
     * 测试服务是否正常运行
     * @return ok
     */
    @GetMapping("/test")
    public Result<?> console() {
        return Result.ok();
    }
}
